package com.qianxun.module.datasource1.common.util;

import java.util.Random;

/**
 * 短信验证码生成
 * @author: huwei
 * @date: 2019/12/5 16:43
 * @version: 1.0.0
 */
public class SmsCodeGenerator {

    /**
     * 短信验证码基数
     */
    private static final int[] BASE_NUMBER = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    /**
     * 短信验证码长度
     */
    private static final int SMS_CODE_LENGTH = 6;

    public static String randomCode() {
        return randomCode(SMS_CODE_LENGTH);
    }

    public static String randomCode(int codeLength) {
        StringBuffer result = new StringBuffer();
        Random random = new Random();
        for (int i = 0; i < codeLength; ++i) {
            result.append(BASE_NUMBER[random.nextInt(10)]);
        }
        return result.toString();
    }
}
